package com.sync.syncmasterdata;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.sync.syncmasterdata.customer.pojo.bip.CustomerAssign;
import com.sync.syncmasterdata.customer.pojo.bip.CustomerForBip;
import com.sync.syncmasterdata.customer.pojo.bip.CustomerForBipUpdate;
import com.sync.syncmasterdata.defdoc.domain.BrandForBipDTO;
import com.sync.syncmasterdata.defdoc.domain.DefDocDTO;
import com.sync.syncmasterdata.product.pojo.bip.*;
import com.sync.syncmasterdata.pubdomain.BipResponse;
import com.sync.syncmasterdata.util.BipRequestUtil;
import com.sync.syncmasterdata.util.NormalUtil;
import com.sync.syncmasterdata.vendor.pojo.bip.SupplierAssign;
import com.sync.syncmasterdata.vendor.pojo.bip.SupplierForBip;
import com.sync.syncmasterdata.vendor.pojo.bip.SupplierForBipUpdate;
import lombok.extern.slf4j.Slf4j;
import nccloud.open.api.auto.token.itf.IAPIUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.*;


@SpringBootTest
@Slf4j
class SyncMasterDataApplicationTestsBIP {


    @Autowired
    private BipRequestUtil bipAuthUtil;

    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private BipRequestUtil bipRequestUtil;


    @Test
    public void getAccessTokenObjectForTest() {
        try {
            IAPIUtils utils = bipAuthUtil.getAPIUtil();
            System.out.println(utils.getToken());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 客户列表获取
     */
    @Test
    public void getCustomerBaseInfo() {
        IAPIUtils utils = bipAuthUtil.getAPIUtil();
        try {
            String accessToken = utils.getToken();
            String url = "nccloud/api/uapbd/customermanage/querycustomerinfo/queryCustomerBaseInfo";
            utils.setApiUrl(url);
            Map<String, Object> ufinterface = new HashMap<>();
            Map<String, Object> data = new HashMap<>();
            Map<String, Object> pageInfo = new HashMap<>();
            pageInfo.put("pageIndex", 0);
            pageInfo.put("pageSize", 5000);
            List<String> pkOrg = new ArrayList<>();
//            pkOrg.add("ASD");
            data.put("pk_org", new ArrayList<>());
            data.put("pk_group", "BS");
            data.put("code", new ArrayList<>());
            data.put("name", new ArrayList<>());
//            data.put("taxpayerid", new ArrayList<>());
//            data.put("pk_custclass", new ArrayList<>());
            data.put("ts", null);
//            List<String> _customer = new ArrayList<>();
//            _customer.add("1001A110000000008LET");
//            data.put("id", _customer);
            data.put("enablestate", null);
            data.put("pageInfo", pageInfo);
            ufinterface.put("sender", "syncMaster");
            ufinterface.put("data", data);
            Map<String, Object> reqMap = new HashMap<>();
            reqMap.put("ufinterface", ufinterface);
            String params = objectMapper.writeValueAsString(reqMap);
            String ret = utils.getAPIRetrun(accessToken, params);
            System.out.println("临时打印输出====>>>>" + ret);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 供应商列表获取
     */
    @Test
    public void getSupplierBaseInfo() {
        IAPIUtils utils = bipAuthUtil.getAPIUtil();
        try {
            String accessToken = utils.getToken();
            String url = "nccloud/api/uapbd/supplierquery/supplierbaseinfo/supplierbaseinfoquery";
            utils.setApiUrl(url);
            Map<String, Object> ufinterface = new HashMap<>();
            Map<String, Object> data = new HashMap<>();
            Map<String, Object> pageInfo = new HashMap<>();
            pageInfo.put("pageIndex", 0);
            pageInfo.put("pageSize", 5000);
            List<String> pkOrg = new ArrayList<>();
//            pkOrg.add("ASD");
            data.put("pk_org", new ArrayList<>());
            data.put("pk_group", "BS");
            data.put("code", new ArrayList<>());
            data.put("name", new ArrayList<>());
//            data.put("taxpayerid", new ArrayList<>());
//            data.put("pk_supplierclass", new ArrayList<>());
            data.put("ts", null);
            data.put("enablestate", null);
//            data.put("pageInfo", pageInfo);
            ufinterface.put("sender", "default");
            ufinterface.put("data", data);
            Map<String, Object> reqMap = new HashMap<>();
            reqMap.put("ufinterface", ufinterface);
            String params = objectMapper.writeValueAsString(reqMap);

            String ret = utils.getAPIRetrun(accessToken, params);
            System.out.println("临时打印输出====>>>>" + ret);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 新增客户信息
     */
    @Test
    public void addCustomerForTest() {
        IAPIUtils utils = bipAuthUtil.getAPIUtil();
        try {
            String accessToken = utils.getToken();
            String url = "nccloud/api/uapbd/customermanage/customer/add";
            CustomerForBip.CustomerBill.CustomerBillHead customerBillHead = new CustomerForBip.CustomerBill.CustomerBillHead();
            customerBillHead.setMemo("测试推送信息");
            customerBillHead.setName("接口推送客户2");
//            bipHeadBip.setEname("接口推送客户1");
            customerBillHead.setShortname("接口推送客户1");
            customerBillHead.setCustprop(0);
            customerBillHead.setCode("AB0001");
            customerBillHead.setPk_group("BS");
            customerBillHead.setPk_org("BS");
            customerBillHead.setPk_country("CN");
            customerBillHead.setPk_custclass("01");
            customerBillHead.setDef1("自定义项1推送");
            customerBillHead.setDef2("自定义项2推送");

            //链式处理
            CustomerForBip.CustomerBill customerBill = CustomerForBip.CustomerBill.builder().billhead(customerBillHead).build();
            CustomerForBip customerBip = CustomerForBip.builder().bill(customerBill).build();

            Map<String, Object> ufinterface = bipRequestUtil.requestMap("ufinterface", customerBip);
            System.out.println("打印推送请求=>>>>>" + objectMapper.writeValueAsString(ufinterface));
            utils.setApiUrl(url);
            String ret = utils.getAPIRetrun(accessToken, objectMapper.writeValueAsString(ufinterface));
            System.out.println("打印请求返回====>>>" + ret);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 更新客户信息
     */
    @Test
    public void updateCustomerForTest() {
        IAPIUtils utils = bipAuthUtil.getAPIUtil();
        try {
            String accessToken = utils.getToken();
            String url = "nccloud/api/uapbd/customermanage/customer/update";
            CustomerForBipUpdate.CustomerBill.CustomerBillHead customerBillHeadUpdate = new CustomerForBipUpdate.CustomerBill.CustomerBillHead();

            customerBillHeadUpdate.setName("痞子姚客户更新3");
            customerBillHeadUpdate.setShortname("痞子姚客户更新3");
            customerBillHeadUpdate.setCode("AB0002");
            customerBillHeadUpdate.setPk_custclass("01");

            //链式处理
            CustomerForBipUpdate.CustomerBill customerBill = CustomerForBipUpdate.CustomerBill.builder().billhead(customerBillHeadUpdate).build();
            customerBill.setId("AB0002");

            CustomerForBipUpdate customerBipUpdate = CustomerForBipUpdate.builder().bill(customerBill).build();
            Map<String, Object> ufinterface = bipRequestUtil.requestMap("ufinterface", customerBipUpdate);
            System.out.println("打印推送请求=>>>>>" + objectMapper.writeValueAsString(ufinterface));
            utils.setApiUrl(url);
            String ret = utils.getAPIRetrun(accessToken, objectMapper.writeValueAsString(ufinterface));
            System.out.println("打印请求返回====>>>" + ret);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    @Test
    public void supplierAddForTest() {
        IAPIUtils utils = bipAuthUtil.getAPIUtil();
        try {
            String accessToken = utils.getToken();
            String url = "nccloud/api/uapbd/suppliermanage/supplier/add";
            utils.setApiUrl(url);
            SupplierForBip.SupplierBill.SupplierBillHead supplierBillHead = new SupplierForBip.SupplierBill.SupplierBillHead();

            supplierBillHead.setCode("SU001");
            supplierBillHead.setName("痞子姚的供应商");
            supplierBillHead.setPk_group("BS");
            supplierBillHead.setPk_org("BS");
            supplierBillHead.setPk_supplierclass("N3301");
//            supplierBillHead.setPk_areacl("5101");
            SupplierForBip.SupplierBill supplierBill = SupplierForBip.SupplierBill.builder().billhead(supplierBillHead).build();
            SupplierForBip supplier = SupplierForBip.builder().bill(supplierBill).build();

            Map<String, Object> ufinterface = NormalUtil.assembleMap("ufinterface", supplier);
            System.out.println("打印推送请求=>>>>>" + objectMapper.writeValueAsString(ufinterface));
            String ret = utils.getAPIRetrun(accessToken, objectMapper.writeValueAsString(ufinterface));
            System.out.println("打印请求返回====>>>" + ret);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Test
    public void supplierUpdateForTest() {
        IAPIUtils utils = bipAuthUtil.getAPIUtil();
        try {
            String accessToken = utils.getToken();
            String url = "nccloud/api/uapbd/suppliermanage/supplier/update";
            utils.setApiUrl(url);
            SupplierForBipUpdate.SupplierBill.SupplierBillHead supplierBillHead = new SupplierForBipUpdate.SupplierBill.SupplierBillHead();
            supplierBillHead.setCode("SU001");
            supplierBillHead.setName("痞子姚的供应商-更新");
            supplierBillHead.setPk_group("BS");
            supplierBillHead.setPk_org("BS");
            supplierBillHead.setPk_supplierclass("N3301");

//            supplierBillHead.setPk_areacl("5101");
            SupplierForBipUpdate.SupplierBill supplierBill = SupplierForBipUpdate.SupplierBill.builder().billhead(supplierBillHead).build();
            supplierBill.setId("0001A2100000000016GQ197ed3b6efe0supplier179130");

            SupplierForBipUpdate supplier = SupplierForBipUpdate.builder().bill(supplierBill).build();
            supplier.setId("");
            Map<String, Object> ufinterface = NormalUtil.assembleMap("ufinterface", supplier);
            System.out.println("打印推送请求=>>>>>" + objectMapper.writeValueAsString(ufinterface));
            String ret = utils.getAPIRetrun(accessToken, objectMapper.writeValueAsString(ufinterface));
            System.out.println("打印请求返回====>>>" + ret);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Test
    public void assignSupplierForTest(){
        try {
            IAPIUtils utils = bipAuthUtil.getAPIUtil();
            String accessToken = utils.getToken();
            String[] argOrg = {"BS01"};
            String supplierCode = "N33012193";
            IAPIUtils iapiUtils= bipRequestUtil.getAPIUtil();
            String url="nccloud/api/uapbd/suppliermanage/supplierbaseinfo/assign";
            iapiUtils.setApiUrl(url);
            SupplierAssign.AssignData assignData=SupplierAssign.AssignData.builder().code(Arrays.asList(supplierCode)).pk_org(Arrays.asList(argOrg)).build();
            SupplierAssign supplierAssign=SupplierAssign.builder().data(assignData).build();
            Map<String, Object> ufinterface = NormalUtil.assembleMap("ufinterface", supplierAssign);
            log.info("分配请求查看===>>>{}", objectMapper.writeValueAsString(ufinterface));
            String ret = iapiUtils.getAPIRetrun(accessToken, objectMapper.writeValueAsString(ufinterface));
            log.info("分配接口返回===>>>{}", ret);
            BipResponse<String> bipResponse=objectMapper.readValue(ret,BipResponse.class);
            if(bipResponse.getSuccess()){
                log.info("分配成功");
            }else{
                log.info("推送Bip供应商信息后分配（新增）出错：");
            }
        } catch (Exception e) {
            log.info("推送供应商分配异常");
            log.info("推送Bip供应商信息后分配（新增）出错："+e.toString());
        }
    }

    @Test
    public void productAddForTest() {
        IAPIUtils utils = bipAuthUtil.getAPIUtil();
        try {
            String accessToken = utils.getToken();
            String url = "nccloud/api/uapbd/material/material/add";
            utils.setApiUrl(url);
            //辅助单位
            ProductForBip.ProductBill.ProductMaterialConvert.ProductMaterialConvertItem unitItem = new ProductForBip.ProductBill.ProductMaterialConvert.ProductMaterialConvertItem();
            unitItem.setMeasrate("mL");
            unitItem.setPk_measdoc("mL");
            unitItem.setMeasrate("1/1");
            ProductForBip.ProductBill.ProductMaterialConvert productForBipMaterial = ProductForBip.ProductBill.ProductMaterialConvert.builder().item(Arrays.asList(unitItem)).build();
            //主要对象
            ProductForBip.ProductBill.ProductBillHead productBillHead = new ProductForBip.ProductBill.ProductBillHead();
            productBillHead.setPk_marbasclass("MAYW");
            productBillHead.setName("接口推送测试1228");
            productBillHead.setMaterialshortname("接口推送测试12");
            productBillHead.setEname("abc");
            productBillHead.setPk_measdoc("010");
            productBillHead.setPk_mattaxes("CN001");
            productBillHead.setMaterialspec("型号1228");
            productBillHead.setMaterialtype("型号1228");
            productBillHead.setCode("24448");
            productBillHead.setVmanufacturer_148("痞子姚厂");
            productBillHead.setProdarea("国内");
            productBillHead.setMaterialconvert(productForBipMaterial);

            ProductForBip.ProductBill productBill = ProductForBip.ProductBill.builder().billhead(productBillHead).build();
            ProductForBip product=ProductForBip.builder().bill(productBill).build();

            Map<String, Object> req = bipAuthUtil.requestMap("ufinterface", product);
            System.out.println("打印推送请求=>>>>>" + objectMapper.writeValueAsString(req));
            String ret = utils.getAPIRetrun(accessToken, objectMapper.writeValueAsString(req));
            System.out.println("打印请求返回=>>>>>" + objectMapper.writeValueAsString(ret));
        } catch (Exception e) {
            log.info("异常");
        }
    }

    /**
     * 产品分配测试 不能默认上下级直接分配,要手动一条条
     */
    @Test
    public void assignProduct() {
        IAPIUtils utils = bipAuthUtil.getAPIUtil();
        try {
            String accessToken = utils.getToken();
            String url = "nccloud/api/uapbd/material/material/assignMaterial";
            utils.setApiUrl(url);
            Map<String, Object> ufinterface = new HashMap<>();
            Map<String, Object> data = new HashMap<>();
            data.put("code", "24445");
            data.put("assignorgs", Arrays.asList("BS01", "BS0101", "BS0110", "BS0114", "BS0115"));
            data.put("pk_org", "BS");
            ufinterface.put("sender", "syncMaster");
            ufinterface.put("data", data);
            Map<String, Object> req = new HashMap<>();
            req.put("ufinterface", ufinterface);
            System.out.println("打印推送请求=>>>>>" + objectMapper.writeValueAsString(req));
            String ret = utils.getAPIRetrun(accessToken, objectMapper.writeValueAsString(req));
            System.out.println("打印请求返回=>>>>>" + objectMapper.writeValueAsString(ret));
        } catch (Exception e) {
            log.info("异常");
        }
    }

    @Test
    public void assignCustomer() {
        IAPIUtils utils = bipAuthUtil.getAPIUtil();
        try {
            String accessToken = utils.getToken();
            String url = "nccloud/api/uapbd/customermanageext/customer/assign";
            utils.setApiUrl(url);
            //链式调用
            //定义组织
            String[] orgs = {"BS01", "BS0101", "BS0110", "BS0114", "BS0115"};
            String[] customers = {"0001"};
            CustomerAssign.AssignData assignData=CustomerAssign.AssignData.builder().customer(Arrays.asList(customers)).org(Arrays.asList(orgs)).build();
            CustomerAssign customerAssign = CustomerAssign.builder().data(assignData).sender("123").build();

            System.out.println(objectMapper.writeValueAsString(customerAssign));

//            Map<String, Object> ufinterface = new HashMap<>();
//            Map<String, Object> data = new HashMap<>();
//            data.put("code", "24445");
//            data.put("assignorgs", Arrays.asList("BS01","BS0101","BS0110","BS0114","BS0115"));
//            data.put("pk_org", "BS");
//            ufinterface.put("sender", "syncMaster");
//            ufinterface.put("data", data);
//            Map<String, Object> req = new HashMap<>();
//            req.put("ufinterface", ufinterface);
//            System.out.println("打印推送请求=>>>>>" + objectMapper.writeValueAsString(req));
//            String ret=utils.getAPIRetrun(accessToken, objectMapper.writeValueAsString(req));
//            System.out.println("打印请求返回=>>>>>" + objectMapper.writeValueAsString(ret));
        } catch (Exception e) {
            log.info("异常");
        }
    }

    /**
     * 物料 库存页签
     */
    @Test
    public void stockProductAdd() {
        IAPIUtils utils = bipAuthUtil.getAPIUtil();
        try {
            String accessToken = utils.getToken();
            String url = "nccloud/api/uapbd/material/materialstock/add";
            utils.setApiUrl(url);
            Map<String, Object> ufinterface = new HashMap<>();

            ProductStockForBip.StockBill.StockBillHead stockBillHead = new ProductStockForBip.StockBill.StockBillHead();
            stockBillHead.setPk_material("24445");
            stockBillHead.setPk_org("BS0115");
            stockBillHead.setPk_org_m("BS0115");
            stockBillHead.setAbctype("B");
            stockBillHead.setChkfreeflag("Y");
            stockBillHead.setStockbycheck("N");
            stockBillHead.setWholemanaflag("Y");
            stockBillHead.setPk_stordoc("2");
            stockBillHead.setQualitymanflag("Y");
            stockBillHead.setQualityunit("1");
            stockBillHead.setQualitynum("18");
            ProductStockForBip.StockBill stockBill=ProductStockForBip.StockBill.builder().billhead(stockBillHead).build();
            ProductStockForBip product = ProductStockForBip.builder().bill(stockBill).build();
            ufinterface = NormalUtil.assembleMap("ufinterface", product);
            System.out.println("打印推送请求=>>>>>" + objectMapper.writeValueAsString(ufinterface));
            String ret = utils.getAPIRetrun(accessToken, objectMapper.writeValueAsString(ufinterface));
            BipResponse<HashMap> bipResponse = objectMapper.readValue(ret, BipResponse.class);
            Map<String, Object> resUfinterface = bipResponse.getData();
            if(resUfinterface instanceof Map){
                Map<String, Object> _res =(Map<String,Object>) resUfinterface.get("ufinterface");
                if(_res.get("successful").equals("Y")){
                    System.out.println("推送成功");
                }
            }
            System.out.println("打印请求返回=>>>>>" + objectMapper.writeValueAsString(ret));
        } catch (Exception e) {
            System.out.println("异常");
        }
    }

    @Test
    public void prodProductAdd() {
        IAPIUtils utils = bipAuthUtil.getAPIUtil();
        try {
            String accessToken = utils.getToken();
            String url = "nccloud/api/uapbd/material/materialprod/add";
            utils.setApiUrl(url);
            Map<String, Object> ufinterface = new HashMap<>();

            ProductProdForBip.ProdBill.ProdBillHead prodBillHead = new  ProductProdForBip.ProdBill.ProdBillHead();
            prodBillHead.setPk_material("24445");
            prodBillHead.setPk_org("BS0110");
            prodBillHead.setPk_org_m("BS0110");
            prodBillHead.setSfcbdx("N");
            prodBillHead.setMaterstate("0");
            prodBillHead.setSfcbdxtype("Sys001");
            ProductProdForBip.ProdBill prodBill=ProductProdForBip.ProdBill.builder().billhead(prodBillHead).build();
            ProductProdForBip product = ProductProdForBip.builder().bill(prodBill).build();
            ufinterface = NormalUtil.assembleMap("ufinterface", product);
            System.out.println("打印推送请求=>>>>>" + objectMapper.writeValueAsString(ufinterface));
            String ret = utils.getAPIRetrun(accessToken, objectMapper.writeValueAsString(ufinterface));
            BipResponse<HashMap> bipResponse = objectMapper.readValue(ret, BipResponse.class);
            Map<String, Object> resUfinterface = bipResponse.getData();
            if(resUfinterface instanceof Map){
                Map<String, Object> _res =(Map<String,Object>) resUfinterface.get("ufinterface");
                if(_res.get("successful").equals("Y")){
                    System.out.println("推送成功");
                }else{
                    System.out.println("推送失败");
                }
            }
            System.out.println("打印请求返回=>>>>>" + objectMapper.writeValueAsString(ret));
        } catch (Exception e) {
            System.out.println("异常");
        }
    }

    /**
     * 库存页签 更新的方法
     */
    @Test
    public void stockProductUpdate() {
        IAPIUtils utils = bipAuthUtil.getAPIUtil();
        try {
            String accessToken = utils.getToken();
            String url = "nccloud/api/uapbd/material/materialstock/update";
            utils.setApiUrl(url);
            ProductStockForBip.StockBill.StockBillHead stockBillHead = new ProductStockForBip.StockBill.StockBillHead();
            stockBillHead.setPk_material("24445");
            stockBillHead.setPk_org("BS01");
            stockBillHead.setPk_org_m("BS01");
            stockBillHead.setAbctype("B");
            stockBillHead.setChkfreeflag("Y");
            stockBillHead.setStockbycheck("N");
            stockBillHead.setWholemanaflag("Y");
            stockBillHead.setPk_stordoc("0001"); //1001A11000000000291R
//            productForBipStockHead.setPk_suplystockorg("BS01");
            stockBillHead.setQualitymanflag("Y");
            stockBillHead.setQualityunit("1");
            stockBillHead.setQualitynum("18");
            ProductStockForBip.StockBill stockBill=ProductStockForBip.StockBill.builder().billhead(stockBillHead).build();
            ProductStockForBip product = ProductStockForBip.builder().bill(stockBill).build();
            Map<String, Object> ufinterface = NormalUtil.assembleMap("ufinterface", product);
            System.out.println("打印推送请求=>>>>>" + objectMapper.writeValueAsString(ufinterface));
            String ret = utils.getAPIRetrun(accessToken, objectMapper.writeValueAsString(ufinterface));
            System.out.println("打印请求返回=>>>>>" + objectMapper.writeValueAsString(ret));
        } catch (Exception e) {
            System.out.println("异常");
        }
    }

    @Test
    public void getMaterialInfo() {
        IAPIUtils utils = bipAuthUtil.getAPIUtil();
        try {
            String accessToken = utils.getToken();
            String url = "nccloud/api/uapbd/material/material/queryMaterial";
            utils.setApiUrl(url);
            Map<String, Object> ufinterface = new HashMap<>();
            Map<String, Object> data = new HashMap<>();
            Map<String, Object> pageInfo = new HashMap<>();
            pageInfo.put("pageIndex", 0);
            pageInfo.put("pageSize", 10);
            List<String> pkOrg = new ArrayList<>();
//            pkOrg.add("ASD");
            data.put("pk_org", new ArrayList<>());
            data.put("pk_group", "BS");
            data.put("code", new ArrayList<>());
            data.put("name", new ArrayList<>());
//            data.put("taxpayerid", new ArrayList<>());
//            data.put("pk_custclass", new ArrayList<>());
            data.put("ts", null);
//            List<String> _customer = new ArrayList<>();
//            _customer.add("1001A110000000008LET");
//            data.put("id", _customer);
            data.put("enablestate", null);
            data.put("pageInfo", pageInfo);
            ufinterface.put("sender", "syncMaster");
            ufinterface.put("data", data);
            Map<String, Object> reqMap = new HashMap<>();
            reqMap.put("ufinterface", ufinterface);
            String params = objectMapper.writeValueAsString(reqMap);
            String ret = utils.getAPIRetrun(accessToken, params);
            System.out.println("临时打印输出====>>>>" + ret);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 自定义项测试
     */
    @Test
    public void defdocForTest() {
        IAPIUtils utils = bipAuthUtil.getAPIUtil();
        try {
            String accessToken = utils.getToken();
            String url = "nccloud/api/riamm/defdocmanage/defdoc/add";
            utils.setApiUrl(url);
            DefDocDTO.DefDocBill.DefDocBillHead defDocBillHead = new DefDocDTO.DefDocBill.DefDocBillHead();
            //先测试生产厂商
            defDocBillHead.setPk_defdoclist("BD006_0xx");
            defDocBillHead.setCode("痞子姚的厂商2");
            defDocBillHead.setName("痞子姚的厂商2");
            defDocBillHead.setPk_group("BS");
            defDocBillHead.setPk_org("BS");
            DefDocDTO.DefDocBill defDocBill = DefDocDTO.DefDocBill.builder().billhead(defDocBillHead).id("").build();
            DefDocDTO defDocDTO = DefDocDTO.builder().bill(Arrays.asList(defDocBill)).build();
            Map<String, Object> ufinterface = NormalUtil.assembleMap("ufinterface", defDocDTO);
            System.out.println("打印推送请求=>>>>>" + objectMapper.writeValueAsString(ufinterface));
            String ret = utils.getAPIRetrun(accessToken, objectMapper.writeValueAsString(ufinterface));
            System.out.println("临时打印输出====>>>>" + ret);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 品牌测试
     */
    @Test
    public void brandForTest() {
        IAPIUtils utils = bipAuthUtil.getAPIUtil();
        try {
            String accessToken = utils.getToken();
            String url = "nccloud/api/uapbd/brankmanage/branddoc/add";
            utils.setApiUrl(url);
            BrandForBipDTO.BrandForBipBill.BrandForBipBillHead brandForBipBillHead = new BrandForBipDTO.BrandForBipBill.BrandForBipBillHead();
            brandForBipBillHead.setCode("痞子姚拍拍");
            brandForBipBillHead.setName("痞子姚拍拍");
            BrandForBipDTO.BrandForBipBill bill = BrandForBipDTO.BrandForBipBill.builder().billhead(brandForBipBillHead).build();
            BrandForBipDTO brandForBipDTO = BrandForBipDTO.builder().bill(bill).build();
            Map<String, Object> ufinterface = NormalUtil.assembleMap("ufinterface", brandForBipDTO);

            System.out.println("打印推送请求=>>>>>" + objectMapper.writeValueAsString(ufinterface));
            String ret = utils.getAPIRetrun(accessToken, objectMapper.writeValueAsString(ufinterface));
            System.out.println("临时打印输出====>>>>" + ret);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Test
    public void getDefdocForTest() {
        IAPIUtils utils = bipAuthUtil.getAPIUtil();
        try {
            String accessToken = utils.getToken();
            String url = "nccloud/api/riamm/defdocquery/defdoc/queryDefdoc";
            utils.setApiUrl(url);
            Map<String, Object> ufinterface = new HashMap<>();
            Map<String, Object> data = new HashMap<>();
            List<String> pk_defdoclist = new ArrayList<>();
            pk_defdoclist.add("BD006_0xx");
            data.put("pk_org", new ArrayList<>());
            data.put("pk_group", "BS");
//            data.put("enablestate", Arrays.asList("2"));
            data.put("enablestate", null);
            data.put("pk_defdoclist", pk_defdoclist);
            ufinterface.put("sender", "syncMaster");
            ufinterface.put("data", data);
            Map<String, Object> reqMap = new HashMap<>();

            reqMap.put("ufinterface", ufinterface);
            String params = objectMapper.writeValueAsString(reqMap);

            System.out.println("打印推送请求=>>>>>" + params);
            String ret = utils.getAPIRetrun(accessToken, params);
            System.out.println("临时打印输出====>>>>" + ret);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
